package com.cf.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.cf.domain.pojo.*;
import com.cf.domain.vo.TeamOrderVO;
import com.cf.domain.vo.TeamVO;
import com.cf.domain.vo.UserVO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @Author lzqinga@126.com
 * @Date 2024/11/12  19:41
 */
public interface TeamOrderMapper extends BaseMapper<TeamOrder> {

    @Select("SELECT user_id, ground_id, sort, is_score FROM t_team_order WHERE ground_id = #{groundId} ORDER BY sort")
    @Results({
            @Result(property = "team", column = "user_id", one = @One(select = "com.cf.mapper.TeamMapper.getTeamByUserId", fetchType= FetchType.DEFAULT)),
            @Result(property = "user", column = "user_id", one = @One(select = "com.cf.mapper.UserMapper.getUserById", fetchType= FetchType.DEFAULT)),
            @Result(property = "ground", column = "ground_id", one = @One(select = "com.cf.mapper.GroundMapper.getGroundById", fetchType= FetchType.DEFAULT))
    })
    List<TeamOrderVO> getListByGroundId(Long groundId);

    @Select("SELECT tt.user_id, tt.ground_id, tt.sort, tt.score, tt.is_score, tu.type FROM t_team_order tt left join t_user tu ON tt.user_id = tu.id " +
            "WHERE tt.is_score = 1 AND tt.user_id = #{userId} ORDER BY tt.sort DESC")
    @Results({
            @Result(property = "team", column = "user_id", one = @One(select = "com.cf.mapper.TeamMapper.getTeamByUserId", fetchType= FetchType.DEFAULT)),
            @Result(property = "user", column = "user_id", one = @One(select = "com.cf.mapper.UserMapper.getUserById", fetchType= FetchType.DEFAULT)),
            @Result(property = "ground", column = "ground_id", one = @One(select = "com.cf.mapper.GroundMapper.getGroundById", fetchType= FetchType.DEFAULT))
    })
    List<TeamOrderVO> getListByUserId(Long userId);

}
